package com.example;

import java.util.Arrays;

public class ArrayCreate {

    public static void main(String[] args) {
        ArrayCreate arrayCreate = new ArrayCreate();
        arrayCreate.testArrayCreate();
        arrayCreate.testMultiArray();
    }

    void testArrayCreate() {
        int[] numbers = {1, 2, 3, 4, 5};

        int[] numbers2 = new int[5];
        // numbers2[0] = 1;
        // numbers2[1] = 2;
        // numbers2[2] = 3;
        // numbers2[3] = 4;
        // numbers2[4] = 5;

        int[] numbers3 = new int[]{1, 2, 3, 4, 5};

        double[] numbers4 = new double[]{1.1, 2.2, 3.3, 4.4, 5.5};
        System.out.println(Arrays.toString(numbers));
        System.out.println(Arrays.toString(numbers2));
        System.out.println(Arrays.toString(numbers3));
        System.out.println(Arrays.toString(numbers4));

        double total = 0;
        double totalTwo = 0;
        for (double d : numbers4) {
            total += d;
        }
        System.out.println("total = " + total);

        for (int i = 0; i < numbers4.length; i++) {
            totalTwo = numbers4[i] + numbers[i] + numbers2[i] + numbers3[i] + totalTwo;
        }
        System.out.println("totalTwo = " + totalTwo);
    }

    // 多维数组
    void testMultiArray() {
        int[][] numbers = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        int[][] numbers2 = new int[3][3];
        numbers2[0][0] = 1;
        numbers2[0][1] = 2;
        numbers2[0][2] = 3;
        numbers2[1][0] = 4;
        numbers2[1][1] = 5;
        numbers2[1][2] = 6;

        int[][] numbers3 = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
        String[][] names = {{"张三", "李四", "王五"}, {"赵六", "孙七", "周八"}, {"吴九", "郑十", "冯十一"}};

        System.out.println(Arrays.toString(numbers));
        System.out.println(Arrays.deepToString(numbers));
        System.out.println(Arrays.deepToString(numbers2));
        System.out.println(Arrays.deepToString(numbers3));
        System.out.println(Arrays.deepToString(names));

      
        class ChangeIt {

            static void doIt(int[] z) {
                z = null;
            }
        }

        class TestIt {

            public static void main(String[] args) {
                int[] myArray = {1, 2, 3, 4, 5};
                ChangeIt.doIt(myArray);
                for (int j = 0; j < myArray.length; j++) {
                    System.out.print(myArray[j] + " ");
                }
            }
        }
    }
}
